package HP.p0911;

import javax.xml.crypto.Data;
import java.io.*;

public class Test {
    public static void main(String[] args) throws Exception {
        // new Test().TestFile2();
        //new Test().TestFileOutPut1();
        //new Test().testDateOutput();
        new Test().testDateOutputBuffer();
    }

    /**
     * 文件输入1:
     */
    public void TestFileInputStream1() throws Exception {

        InputStream fileInputStream = new FileInputStream("D:\\1\\a.log");
        byte[] abb = new byte[1024];

        int a = fileInputStream.read(abb);
        String str = new String(abb);

        System.out.println("a = " + a);
        System.out.println(str);
    }

    /**
     * 文件输入2
     */
    public void TestFile2() throws Exception {
        InputStream is = new FileInputStream("D:\\1\\a.log");
        InputStreamReader isr = new InputStreamReader(is, "GBK");
        int i = isr.read();
        while (i != -1) {
            System.out.print((char) i);
            i = isr.read();
        }

    }

    /**
     * 文件输出
     */
    public void TestFileOutPut1() throws Exception {
        String set = "缉拿天美意";
        OutputStream ops = new FileOutputStream("D:\\1\\a2.log");
        ops.write(set.getBytes());
    }

    /**
     * 文件复制1
     */
    public void TestFileCopy() throws Exception {
        InputStream fis = new FileInputStream("D:\\1\\a.log");
        OutputStream fos = new FileOutputStream("D:\\1\\a444.log");
        byte[] bytes = new byte[1024];
        fis.read(bytes);
        System.out.println("bytes = " + bytes.toString());
        fos.write(bytes);
        fis.close();
        fos.close();
    }

    /*
     * 文件复制2
     */
    public void TestFileCopy2() throws Exception {
        InputStream fis = new FileInputStream("D:\\1\\a.log");
        OutputStream fos = new FileOutputStream("D:\\1\\2555.log");

        int bb = fis.read();
        while (bb != -1) {
            fos.write(bb);
            bb = fis.read();
        }
        fis.close();
        fos.close();
    }

    /**
     * 数据输出
     *
     * @throws FileNotFoundException
     */
    public void testDateOutput() throws IOException {
        FileOutputStream fis = new FileOutputStream("D:\\1\\shujvchu.log");
        OutputStreamWriter writer = new OutputStreamWriter(fis);
        DataOutputStream dos = new DataOutputStream(fis);
        dos.writeBytes("1231313111212gregeegedrg");
        dos.close();
    }

    /**
     * 数据输入
     *
     * @throws FileNotFoundException
     */
    public void testDateInput() throws IOException {
        StringBuilder stringBuilder = new StringBuilder();
        FileInputStream fis = new FileInputStream("D:\\1\\shujvchu.log");

        DataInputStream dia = new DataInputStream(fis);

        byte[] bytes = new byte[1024];
        dia.read(bytes);
        System.out.println("bytes = " + bytes);
        System.out.println(new String(bytes));
    }


    /**
     * 数据输出
     *
     * @throws FileNotFoundException
     */
    public void testDateOutputBuffer() throws IOException {
        FileOutputStream fis = new FileOutputStream("D:\\1\\shujvchu1111.log");
        BufferedOutputStream stream = new BufferedOutputStream(fis);
        stream.write("2132112edasda".getBytes());
        stream.close();
        stream.close();
/*        FileOutputStream fos = new FileOutputStream("D:\\1\\123wer.log");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        bos.write("好好好".getBytes());
        bos.close();
        fos.close();*/
    }

    /**
     * 数据输入
     *
     * @throws FileNotFoundException
     */
    public void testDateInputBuffer() throws IOException {
        StringBuilder stringBuilder = new StringBuilder();
        FileInputStream fis = new FileInputStream("D:\\1\\shujvchu.log");

        DataInputStream dia = new DataInputStream(fis);

        byte[] bytes = new byte[1024];
        dia.read(bytes);
        System.out.println("bytes = " + bytes);
        System.out.println(new String(bytes));
    }


}
